# 多阶段构建

# 构建阶段
FROM node:lts as builder

WORKDIR /app

# 复制 package.json 和 lock 文件
COPY package.json pnpm-lock.yaml* ./

# 安装 pnpm
RUN npm install -g pnpm@8.6.10

# 安装依赖
RUN pnpm install --no-frozen-lockfile

# 复制项目文件
COPY . .

# 执行构建命令
RUN pnpm run build

# 运行阶段
FROM nginx:stable-alpine

# 将构建生成的静态文件从构建阶段复制到 Nginx 服务目录
COPY --from=builder /app/dist /usr/share/nginx/html

# 暴露端口
EXPOSE 80

# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]
